package com.wbl.train.batch.job;

import cn.hutool.core.date.DateUtil;
import com.wbl.train.common.feign.BusinessFeign;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;

/**
 * Author: 王博纶
 * Date: 2024/2/14 15:23
 * FileName: DailyTrainJob
 * Description: 生成15天后的火车的定时任务类
 */
@Slf4j
@DisallowConcurrentExecution
public class DailyTrainJob implements Job {

    @Resource
    BusinessFeign businessFeign;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        log.info("生成15天后的车次数据 开始");
        // 获取当天的时间
        Date now = new Date();
        // 计算15天后的时间
        Date date = DateUtil.offsetDay(now, 15).toJdkDate();
        // 将Date转换成LocalDate类型
        Instant instant = date.toInstant();
        LocalDate localDate = instant.atZone(ZoneId.systemDefault()).toLocalDate();
        //调用生成车次的方法
        businessFeign.genTrain(localDate);
        log.info("生成15天后的车次数据 结束");
    }
}
